package com.gitee.wsl.data.state.repo

import com.gitee.wsl.data.state.KalugaState
import com.gitee.wsl.data.state.defaultLazySharedFlow
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlin.coroutines.CoroutineContext

/**
 * An abstract [BaseHotStateRepo] that uses a [MutableSharedFlow] with a replay cache of `1` and configured with [BufferOverflow.DROP_OLDEST] to back up data.
 * @param State the type of [KalugaState] represented by this repo.
 * @param coroutineContext the [CoroutineContext] used to create a coroutine scope for this state machine. Make sure that if you pass a coroutine context that has sequential execution if you do not want simultaneous state changes. The default Main dispatcher meets these criteria.
 * @see BaseHotStateRepo
 */
abstract class HotStateRepo<State : KalugaState>(coroutineContext: CoroutineContext = Dispatchers.Main.immediate) :
    BaseHotStateRepo<State, MutableSharedFlow<State>>(coroutineContext) {
    final override val lazyMutableSharedFlow: Lazy<MutableSharedFlow<State>> =
        defaultLazySharedFlow()
}